<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	session_start();
	
	$connectingUser = $_POST['userName'];
	$userPW = $_POST['passwort'];
	
	$hostname = $_SERVER['HTTP_HOST'];
	$path = dirname($_SERVER['PHP_SELF']);
	
	include('../config.php');
	
	mysql_connect($host,$username,$password);
	mysql_select_db($database);

	$myUser = mysql_query("SELECT * FROM saufanten WHERE name = '".$connectingUser."'"); // ausführen des selects und speichern in ein resultset
	$myUser = mysql_fetch_array($myUser);
	
	if( $myUser['passHASH'] == md5($userPW) ) {
		$_SESSION['angemeldet'] = true;
		$_SESSION['AUTH_LEVEL'] = $myUser['rechte'];
		$_SESSION['Admin'] = $myUser['name'];
		$_SESSION['AdministrationActive'] = 'true';
	   header('Location: http://'.$hostname.($path == '/' ? '' : $path).'/adminControlPanel.php');
	} else{
		echo ("<script>alert('Das Passwort oder der Nutzername sind nicht korrekt.');</script>");
	}
} // end script
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-de" lang="de-de">

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Wilkommen beim Buchungssystem der Landsmannschaft Preußen !</title>
    <script src="md5.js"></script>
    <script src="administration.js"></script>
    <style type="text/css">
    <style> a img { border:0 } </style>


<link rel="stylesheet" href="http://preussen.net/templates/preussen_template/css/template.css" type="text/css" />
<link href="http://preussen.net/templates/preussen_template/ja_menus/ja_splitmenu/ja.splitmenu.css" rel="stylesheet" type="text/css" />


<!--[if lte IE 6]>
<style type="text/css">
.clearfix {height: 1%;}
img {border: none;}
</style>
<![endif]-->

<!--[if gte IE 7.0]>
<style type="text/css">
.clearfix {display: inline-block;}
</style>
<![endif]-->

<!--[if gt IE 7]>
<link href="http://preussen.net/templates/preussen_template/css/ie8.css" rel="stylesheet" type="text/css" />
<![endif]-->

</head>
<body id="bd" class=" wide fs3" style="background-image: url(http://preussen.net/templates/preussen_template/images/background/pat-1.jpg);" onLoad="getNameList();">

<div id="ja-wrapper">

	<div id="ja-topbar" class="clearfix">
		<div id="ja-pathway"></div>
	</div>

	<!-- BEGIN: HEADER -->
	<div id="ja-header" class="clearfix">

			<h1 class="logo">
				<a href="/index.php" title="Landsmannschaft Preußen"><span>Landsmannschaft Preußen Bierliste</span></a>
			</h1>
		
		<!-- BEGIN: MAIN NAVIGATION -->
		<div id="ja-mainnav">
			<div id="ja-splitmenu" class="mainlevel clearfix">
				<ul>
				  <li class="menu-item0 first-item"><a href="../index.php" class="menu-item0 active first-item" id="menu1" title="Bierliste"><span class="menu-title">Bierliste</span></a></li>
				  <li class="menu-item1 active last-item"><a href="./index.php" class="menu-item1" id="menu53" title="Verwaltung"><span class="menu-title">Verwaltung</span></a></li><li class="menu-item2"></li>
				  </ul>
			</div>	
		</div>


	</div>
	<!-- END: HEADER -->


	<div style="width:927px; overflow:auto; margin:0px auto;  background-color:#FFFFFF">
		<div style="width:760px; overflow:auto; margin:1% auto;  background-color:#FFFFFF">
			<span id="adminArea">
				<form action="index.php" method="post" style="padding:5px; margin:0px auto;">
						<table width="100%" border="0">
							<tr width="500px">  <td> Namen und Kennwort angeben: </td> </tr>
						</table>
						
						<table width="100%" border="0">
								<tr>
									<td width="100px">
										<select id="nameList" name="userName" style="width:180px;" onchange="checkUser();">
												<option>Name wählen…</option>
										</select>
									</td>
									 
									<td width="180px">
											<input type="password" id="PWD" value="xxxxxxxx" name="passwort" /> 
									</td>
									
									<td>
										<input type="submit" value="Anmelden" id ="login" disabled="disabled" /> 
									</td>
								</tr>
						</table>
				</form>
			</span>
		</div>
	</div>  <!--end container-->
	
</div><!-- end warper-->